#pragma once 
#include "Chunk.h"

#include <glad/glad.h> // 包含glad来获取所有的必须OpenGL头文件
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <unordered_map>
#include <fstream>
#include <noise/PerlinNoise.hpp>
#include <unordered_set>
class Chunk;
class ChunkManager
{
private: 
    struct  key_hash{
        std::size_t operator()(const glm::vec2& k) const
        {
            std::size_t h1 = std::hash<float>()(k.x);
            std::size_t h2 = std::hash<float>()(k.y);
            return h1 ^ (h2 << 1);
        }
    };

    struct key_equal{
        bool operator()(const glm::vec2& lhs, const glm::vec2& rhs) const
        {
            return lhs.x == rhs.x && lhs.y == rhs.y;
        }
    };
    std::unordered_map<glm::vec2, Chunk *, key_hash, key_equal> ChunksMap;

   
public:
    ChunkManager();
    ~ChunkManager();
    
    void GenerateChunks(glm::vec2 PlayerPos);
    Chunk * GetChunk(int x, int y);
    // void RemoveChunk(glm::vec2 pos);
    void RenderChunks(Blockshader &shader, Camera &camera);

    


    BlockBase * GetBlock(glm::ivec3 pos);
    // void SetBlock(glm::vec3 pos, Block * block);
    // void RemoveBlock(glm::vec3 pos);

};


